#include <ctime>
#include <fstream>
#include <iostream>

using namespace std;

void bubbleSort(int list[], int listLength) {
    while(listLength--)  {
            bool swapped = false;

            for(int i =0; i < listLength; i++) {
                    if(list[i] > list[++i]) {
                            swap(list[i], list[++i]);
                            swapped = true;
                    }
            }
                if(swapped == false) break;
    }
}
void read_form_file(const char *filename, int a[], int length) {
    ifstream file(filename);
    for(int i=0; i < length; ++i)
        file >> a[i];
}
int main(){

    #define LEN 5000
    int a[LEN];

    read_form_file("m1_sorted.txt", a,LEN);
    unsigned int t_start = clock();
    bubbleSort(a,LEN);
    unsigned int t_finish = clock();
    unsigned int t_work = t_finish - t_start;
    cout<<"m1_sorted " <<t_work<< " milliecondes \n";

    read_form_file("m2_reverse.txt", a,LEN);
    t_start = clock();
    bubbleSort(a, LEN);
    t_finish = clock();
    t_work = t_finish - t_start;
    cout<<"m2_reverse " <<t_work<< " milliecondes \n";

    read_form_file("m3_shuffle.txt", a,LEN);
    t_start = clock();
    bubbleSort(a, LEN);
    t_finish = clock();
    t_work = t_finish - t_start;
    cout<<"m3_shuflle " <<t_work<< " milliecondes \n";


    return 0;
}
